package cn.xiaohuodui.controller;

import cn.xiaohuodui.util.alioss.AliOssUploader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * Created by keepcleargas on 17-6-24.
 */
@Controller
@RequestMapping("/")
public class IndexController {


    @Autowired
    AliOssUploader aliOssUploader;

    /**
     * 跳转到404页面
     */
    @RequestMapping(value = "/404")
    public String notFoundPage() {
        return "404";
    }

    /**
     * 跳转到401页面
     */
    @RequestMapping(value = "/403")
    public String unauthorizedPage() {
        return "403";
    }

    @RequestMapping(value = "/login")
    public String login() {
        return "login";
    }

    @RequestMapping
    public String index(Model model) {
        return "dashboard";
    }


    /**
     * ali oss url访问
     *
     * @return
     */
    @GetMapping(value = "/aliurl/{type}")
    @ResponseBody
    public Map getUrl(@PathVariable("type") int type) {
        return aliOssUploader.generateUrl(type);
    }
}
